package me.zhengjie.modules.system.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.system.domain.Contract;
import me.zhengjie.modules.system.domain.UserInsuranceInfo;
import me.zhengjie.modules.system.service.UserInsuranceInfoService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "保单信息")
@RestController
@RequestMapping("/api/userInsuranceInfo")
@RequiredArgsConstructor
public class UserInsuranceInfoController {
    private final UserInsuranceInfoService userInsuranceInfoService;

    @ApiOperation("新增保单")
    @PostMapping(value = "/save")
    public ResponseEntity<Object> addInfo(@RequestBody UserInsuranceInfo UserInsuranceInfo) {
//        UserInsuranceInfo.setAcceptance("0");
        userInsuranceInfoService.addInfo(UserInsuranceInfo);
        return new ResponseEntity<>(HttpStatus.OK);
    }


    @ApiOperation("查看保单列表")
    @GetMapping(value = "/queryList")
    public ResponseEntity<Object> queryList(String policyNo, String acceptance) {
        List<UserInsuranceInfo> list = userInsuranceInfoService.queryList(policyNo, acceptance);
        return new ResponseEntity<>(list, HttpStatus.OK);
    }

    @ApiOperation("查看保单")
    @GetMapping(value = "/findById")
    public ResponseEntity<Object> findById(Long id) {
        UserInsuranceInfo userInsuranceInfo = userInsuranceInfoService.findById(id);
        return new ResponseEntity<>(userInsuranceInfo, HttpStatus.OK);
    }


    @ApiOperation("删除保单")
    @GetMapping(value = "/delete")
    public ResponseEntity<Object> delete(Long id) {
        userInsuranceInfoService.delete(id);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @ApiOperation("受理")
    @GetMapping(value = "/acceptance")
    public ResponseEntity<Object> acceptance(Long id) {
        userInsuranceInfoService.acceptance(id);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
